<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/page.js"></script>
<title>首页</title>
</head>
<body>
	<jsp:include page="navigation.jsp"></jsp:include>
	<div class="container" style="margin-left: 190px;">
		<div class="topbar-inner">
			<div class="myhead">
				<span class="crumb-name">系统消息管理</span>
			</div>
		</div>
		<div class="topbar-inner">
			<div class="search">
				<div class="input-group">
					<button type="button" id="add_btn" onclick="showalert_add()" class="btn btn-default" style="margin-left: 20px; margin-top: 1px;">新增</button>
				</div>
			</div>
		</div>
		<form id="pageForm" action="noticeinfo" method="post">
			<c:if test="${ page != null }">
				<input type="hidden" value="${ page.pageCount }" id="pageCount" name="pageCount" />
				<input type="hidden" value="${ page.pageIndex }" id="pageIndex" name="pageIndex" />
			</c:if>
		</form>

		<div style="margin: 20px 20px 20px 20px; text-align: center;">
			<table class="table table-bordered table-hover table-striped">
				<thead>
					<tr>
						<!-- 						<th>接收者</th> -->
						<th>标题</th>
						<th>内容</th>
						<th width="10%">操作</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${ list }" var="l">
						<tr>
							<%-- 							<td>${ l.user_id }</td> --%>
							<td>${ l.title }</td>
							<td>${ l.content }</td>
							<td><a href="javascript:" onclick="toDelete(${ l.id })">删除</a></td>
						</tr>
					</c:forEach>

				</tbody>
			</table>
			<c:if test="${ page == null }">
				<div style="font-size: larger;">暂无数据</div>
			</c:if>
			<c:if test="${ page != null && page.pageCount > 1 }">
				<ul id="pagination" class="pagination">

				</ul>
				<script type="text/javascript">
					setPage(document.getElementById("pagination"), parseInt($(
							"#pageCount").val()), parseInt($("#pageIndex")
							.val()));
				</script>
			</c:if>
		</div>
	</div>
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">系统消息发送</h4>
				</div>
				<div class="modal-body">
					<div style="width: 100%; height: 40px;">
						标题：<input type="text" id="modal_title" class="form-control" name="title" />
					</div>
					<div style="width: 100%; height: 40px;">
						内容：<input type="text" id="modal_content" class="form-control" name="content" />
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" onclick="toAdd()">提交</button>
				</div>
			</div>
		</div>
	</div>
	<!-- /.modal -->
</body>
<script type="text/javascript">
	$(function() {
		$('.submenu_5_2').addClass('submenu_native');
	});

	function showalert_add() {
		$("#myModal").modal('show');
	}

	function toAdd() {
		var title = $('#modal_title').val();
		if (title == '') {
			alert('请填写标题！');
			return;
		}
		var content = $('#modal_content').val();
		if (content == '') {
			alert('内容不能为空！');
			return;
		}

		$.ajax({
			type : 'post',
			url : 'publishnotice',
			data : {
				title : title,
				content : content
			},
			success : function(data) {
				if (data != null) {
					if (data.code == 0) {
						alert('发送成功！');
						window.location.reload();
					}
				}

			}
		});
	}

	function toDelete(index) {
	    if (confirm("确定删除？")) {
	    	$.ajax({
	            type : 'post',
	            url: 'noticedelete',
	            data : {id: index}, 
	            success : function (data) {
	                console.log(data);
	                if (data != null) {
	                    if (data.code == 0) {
	                        alert('删除成功！');
	                        window.location.reload();
	                    } else {
	                        alert(data.message);
	                    }
	                    
	                }
	            }
	        });
		}
		}
</script>
</html>